package com.sntk.registermanager.common.infrastructure.resp;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @作者：wgchao
 * @时间：20:22 2020/6/14 0014
 * @用途：
 **/
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ResponseData<T> implements Serializable {

    @ApiModelProperty(value="返回码-200成功",name="code",example="200", required=true)
    private String code;

    @ApiModelProperty(value="返回描述",name="msg",example="success", required=true)
    private String msg;

    @ApiModelProperty(value="返回数据",name="data")
    private T data;

    public static ResponseData success(){
        ResponseData responseData = new ResponseData();
        responseData.code = "200";
        responseData.msg = "success";
        return responseData;
    }

    public static ResponseData success(String message){
        ResponseData responseData = new ResponseData();
        responseData.code = "200";
        responseData.msg = message;
        return responseData;
    }

    public ResponseData setData(T t){
        this.data = t;
        return this;
    }

    public static ResponseData error(String errorMsg){
        ResponseData responseData = new ResponseData();
        responseData.code = "999";
        responseData.msg = errorMsg;
        return responseData;
    }

    public static ResponseData error(String code, String errorMsg){
        ResponseData responseData = new ResponseData();
        responseData.code = code;
        responseData.msg = errorMsg;
        return responseData;
    }
}
